package com.wanxin.wb.module.web.controller;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.io.ResolverUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
import org.springframework.web.servlet.support.RequestContextUtils;

import com.wanxin.wb.common.support.BaseController;

/**
 * 国际化 测试
 * 
 * @author xiaojun.song
 *
 */

@Controller
@RequestMapping("/weixin/demo")
public class LanguageDemoController extends BaseController {

	@Autowired
	SessionLocaleResolver resolver;
	
	

	// @Autowired SessionLocaleResolver resolver;

	@RequestMapping(value = "/doSome/{country}/{language}/test", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView test(HttpServletRequest request,
			HttpServletResponse response,
			 @PathVariable String country, 
			 @PathVariable String language,  
			 @RequestParam(value = "data", required = true) String data) {
        
		//xxx
		String viewName="lanDemo";
		
		ModelAndView view = new ModelAndView();
		String result = "";
		view.addObject("lan", result);
		
		
		view.setViewName(viewName);
		if (country != null) {
			System.out.println("country==" + country);
		}
		if (language != null) {
			System.out.println("language==" + language);
		}
		if("en".equals(language)){
		//	resolver.setLocale(request, response, Locale.ENGLISH);
		}else{
		//	resolver.setLocale(request, response, Locale.CHINA);
		}

		
		//messages/xxx_message
		ResourceBundle resourceBundle = ResourceBundle.getBundle("message",request.getLocale());  
		String welcome = resourceBundle.getString("welcome");  
		System.out.println("||||后台获取  welcome="+welcome);
		
		
		
		return view;

	}
	
	
	@RequestMapping(value = "/doSome/test1", method = RequestMethod.GET)
	@ResponseBody
	public ModelAndView test2(HttpServletRequest request,
			HttpServletResponse response,
			
			@RequestParam(value = "data", required = true) String data) {

		ModelAndView view = new ModelAndView("lanDemo");
		String result = "";
		view.addObject("lan", result);
		String lan=request.getParameter("lan");
		
		
		
		resolver.setLocale(request, response, Locale.ENGLISH);
		
		return view;

	}

}
